<template>
	<view style="containers">
		<!-- <view v-for="sonItem in item.children" class="boxSonItem">
            <view style="display: flex;">
                <view class="file"></view>
                <view style="margin-left: 20rpx;line-height: 50rpx;">{{sonItem.document_name}}</view>
            </view>
            <view style="display: flex;">
                <view class="btn" @click="showPdf(sonItem.document_path)">查看</view>
                <view class="btn" style="margin-left: 10rpx;" @click="sendEmail(sonItem)">发送邮件</view>
            </view>
        </view> -->
		<uni-section class="mb-10" style="margin-bottom: 10rpx" v-for="item in documentDetail"
			:title="item.document_name">
			<template v-slot:right>
				<view style="display: flex">
					<view class="btn" @click="showPdf(item.document_path,item.document_name)">查看</view>
					<view class="btn" style="margin-left: 10rpx" @click="sendEmail(item)">发送邮件</view>
				</view>
			</template>
		</uni-section>
	</view>
	<uni-popup ref="inputDialog" type="dialog">
		<uni-popup-dialog ref="inputClose" mode="input" title="请输入邮箱" placeholder="点击输入邮箱地址" :focus="false"
			@confirm="dialogInputConfirm"></uni-popup-dialog>
	</uni-popup>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		getDocumentList
	} from "@/api/wuLian";
	import {
		sendDocument
	} from "@/api/index.js";
	const inputDialog = ref(null);
	const currtionRow = ref({})
	const params = ref({});
	onLoad((option) => {
		params.value = option;
		console.log("onLoad");
		getList();
	});

	function sendEmail(row) {
		console.log(row, 55);
		currtionRow.value = row;
		inputDialog.value.open();
	}

	function dialogInputConfirm(email) {
		console.log(currtionRow.value, 62);
		// 杨正邮箱是否合格
		const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
		if (re.test(email)) {
			sendDocument({
				document_id: currtionRow.value.id,
				email,
			}).then((e) => {
				// 调接口
				uni.showToast({
					title: "发送成功",
					duration: 2000,
				});
			});
		} else {
			uni.showToast({
				title: "邮箱格式有误",
				duration: 2000,
			});
		}
	}

	function showPdf(url,name) {
		
		uni.navigateTo({
			url: "/chanPin/pages/fileDetail?path=" + url+'&name='+name
		})
		// uni.showLoading({
		// 	title:"加载中"
		// })
		// #ifdef APP-PLUS || MP-WEIXIN
		// uni.downloadFile({
		//   url: url,
		//   success: (res) => {
		//     uni.hideLoading();
		//     // #ifdef APP-PLUS
		//     uni.openDocument({
		//       filePath: res.tempFilePath,
		//       fileType: "pdf",
		//     });
		// #endif

		// #ifdef MP-WEIXIN
		// wx.openDocument({
		//   filePath: res.tempFilePath,
		//   fileType: "pdf",
		// });
		// #endif
		//   },
		//   fail: (err) => {
		//     uni.hideLoading();
		//     uni.showToast({
		//       title: "打开失败",
		//       icon: "none",
		//     });
		//     console.error(err);
		//   },
		// });
		// #endif
	}
	const documentDetail = ref([]);

	function getList() {
		getDocumentList(params.value).then((res) => {
			console.log(res, 21);
			documentDetail.value = res.data;
		});
	}
</script>

<style scoped>
	.containers {
		background-color: #f8f8f8;
	}

	.btn {
		padding: 10rpx 20rpx;
		border: 2rpx solid #e60012;
		background-color: #e60012;
		color: #fff;
		font-size: 24rpx;
		border-radius: 10rpx;
	}
</style>